layui.use(['table', 'admin', 'ax','form'], function () {
    var $ = layui.$;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var form = layui.form;

    /**
     * 档案信息表管理
     */
    var ArchiveInfo = {
        tableId: "archiveInfoTable"
    };

    /**
     * 初始化表格的列
     */
    ArchiveInfo.initColumn = function () {
        return [[
            {type:'checkbox',fixed:'left',width:80},
            {field: 'wjid', width:100,fixed:'left',sort: true, title: '卷宗号'},
            {field: 'mc',width:200,fixed:'left', title: '档案名称'},
            {field: 'dalx',width:120,  title: '档案类型',templet:'#dalx'},
            {field: 'ssrrmc',width:120, title: '所属人'},
            {field: 'mj', width:120, title: '密级',templet:'#mj'},
            {field: 'glnx', width:120, title: '管理年限',templet:'#glnx'},
            {field: 'nd', width:120, title: '年度'},
            {field: 'qsnd', width:120,title: '起始年度'},
            {field: 'jsnd', width:120, title: '结束年度'},
            {field: 'ly', width:120, title: '来源',templet:'#ly'}
        ]];
    };


    /**
     * 点击查询按钮
     */
    ArchiveInfo.search = function () {
        var condi = $.extend({},wheres,form.val('searchForm'));
        table.reload(ArchiveInfo.tableId, {
            where: condi, page: {curr: 1}
        });
    };

    //表单提交事件
    form.on('submit(btnSearch)', function (data) {
        ArchiveInfo.search();
        return false;
    });

    var wheres = {
        "sfyx":"1"
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + ArchiveInfo.tableId,
        url: Feng.ctxPath + Feng.getUrlParam("url"),
        page: true,
        height: "400",
        where:wheres,
        cellMinWidth: 100,
        cols: ArchiveInfo.initColumn()
    });

    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        ArchiveInfo.search();
    });

    // 点击确定
    $('#select').click(function () {
        //点了选中
        var status = table.checkStatus(ArchiveInfo.tableId);
        if(status.data.length == 0) {
            Feng.error("请至少选中一条数据");
            return;
        }
        admin.putTempData("data",status.data);
        admin.putTempData("formOk", true);
        admin.closeThisDialog();
    });


    // 点击关闭
    $('#close').click(function () {
        admin.putTempData("formOk", true);
        admin.closeThisDialog();

    });
});
